package com.mashibing.mashibing.annotation;

import java.util.stream.Stream;

public class T_Annotation {

    public static void main(String[] args) {
        UserController userController = new UserController();
        Class<? extends UserController> aClass = userController.getClass();

        Stream.of(aClass.getDeclaredFields()).forEach(f -> {
            MyAnnotation annotation = f.getAnnotation(MyAnnotation.class);
            if (annotation != null) {
                f.setAccessible(true);
                Class<?> type = f.getType();
                try {
                    Object o = type.newInstance();
                    f.set(userController, o);
                } catch (InstantiationException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        });
        System.out.println(userController.getUserService());

    }
}
